import { _detail } from '../../common/projects'
const WxParse = require('../../libs/wxParse/wxParse.js')
const computedBehavior = require('miniprogram-computed')
const app = getApp()
Component({
  behaviors: [computedBehavior],
  data: {
    id: 0,
    detail: null
  },
  computed: {
    addBar() {
      return /iphone\sx/i.test(app.globalData.phone.toLowerCase())
    },
    btnNum () {
      let nums = 0
      let detail = this.data.detail
      if (detail) {
        if (detail.ShowTel) nums += 1
        if (detail.Recommend) nums += 1
      }
      return nums
    }
  },
  methods: {
    getDetail() {
      let id = this.data.id
      app.loading('加载中')
      _detail(id).then(res => {
        wx.hideLoading()
        let detail = res.data.Project_Main
        let article = detail.Content
        WxParse.wxParse('article', 'html', article, this, 0)
        wx.setNavigationBarTitle({
          title: detail.ProjectName
        })
        this.setData({
          detail
        })
      }).catch(err => {
        wx.hideLoading()
        wx.showModal({
          title: '对不起',
          content: JSON.stringify(err) || '网络错误，请稍后再试',
          showCancel: false
        })
      })
    },
    call () {
      wx.makePhoneCall({
        phoneNumber: this.data.detail.Tel
      })
    },
    gorecommend () {
      wx.navigateTo({
        url: `/pages/recommend/index?pid=${this.data.detail.ID}`
      })
    },
    onLoad(options) {
      this.data.id = options.id
      let title = this.data.id == 1 ? '租售服务' : this.data.id == 2 ? '商业服务' : ''
      this.getDetail()
    },
    onReady() { },
    onShow() { },
    onShareAppMessage() {
      return app.shareInfo
    }
  }
})